package com.webserver.http;

import java.util.HashMap;
import java.util.Map;

/*
记录所有HTTp协议相关
 */
public class HttpContext {
    /*
    所有资源后缀与头信息Content——Type的值得对应的关系
    key：资源后缀名
    Value：Content-Type头对应的值
     */
    private static Map<String, String> mimeMapping = new HashMap<>();

    static {//类第一次加载被调用
        initMimeMapping();
    }

    private static void initMimeMapping() {
        mimeMapping.put("html", "text/html");
        mimeMapping.put("css", "text/css");
        mimeMapping.put("js", "application/javascript");
        mimeMapping.put("png", "image/png");
        mimeMapping.put("jpg", "image/jpg");
        mimeMapping.put("gif", "image/gif");
    }

    //根据资源后缀名获取头信息Content—-Type的值
    public static String getMimeType(String ext) {
        return mimeMapping.get(ext);
    }

    public static void main(String[] args) {
        String  type = getMimeType("png");
        System.out.println(type);
    }
}
